/** @file               sw_list.h
 *  @copyright          Copyright (C) 2006-2026 flyfish (tenggui_fu@126.com)
 *  @brief              This file is part of the swallow library
 *  @author             $Author: flyfish $
 *  @version            $Rev: 385 $
 *  @date               $Date: 2016-12-22 00:12:05 +0800 (周四, 22 12月 2016) $
 */
#ifndef __SW_LIST_H__
#define __SW_LIST_H__

#ifdef SW_V_WITH_LSTLIB

#ifdef __cplusplus
extern "C" {
#endif

/** @brief  Node of a linked list.
 */
typedef struct _SW_NODE
{
    struct _SW_NODE *next;		/**< Points at the next node in the list */
    struct _SW_NODE *prev;	    /**< Points at the previous node in the list */
}SW_NODE;

/** @brief  Header for a linked list.
 */
typedef struct _SW_LIST
{
    SW_NODE node;			    /**< Header list node */
    SW_INT count;			    /**< Number of nodes in list */
}SW_LIST;

SW_API SW_RET SW_InitListAPI(SW_VOID);
SW_API SW_RET SW_RunListAPI(SW_VOID);
SW_API SW_RET SW_StopListAPI(SW_VOID);
SW_API SW_RET SW_ExitListAPI(SW_VOID);
SW_API SW_RET SW_InitList(SW_LIST *pList);
SW_API SW_NODE *SW_GetFirstNode(const SW_LIST *pList);
SW_API SW_NODE *SW_GetLastNode(const SW_LIST *pList);
SW_API SW_NODE *SW_TakeFirstNode(SW_LIST *pList);
SW_API SW_NODE *SW_TakeLastNode(SW_LIST *pList);
SW_API SW_NODE *SW_GetNStepNode(const SW_NODE *pNode, SW_INT32 step);
SW_API SW_NODE *SW_GetNthNode(const SW_LIST *pList, SW_UINT32 index);
SW_API SW_NODE *SW_GetNextNode(const SW_NODE *pNode);
SW_API SW_NODE *SW_GetPrevNode(const SW_NODE *pNode);
SW_API SW_UINT32 SW_GetNodeCount(const SW_LIST *pList);
SW_API SW_UINT32 SW_FindNode(const SW_LIST *pList, const SW_NODE *pNode);
SW_API SW_RET SW_AddNode(SW_LIST *pList, SW_NODE *pNode);
SW_API SW_RET SW_InsertNode(SW_LIST *pList, SW_NODE *pPrev, SW_NODE *pNode);
SW_API SW_RET SW_RemoveNode(SW_LIST *pList, SW_NODE *pNode);
SW_API SW_RET SW_ConcatList(SW_LIST *pDstList, SW_LIST *pAddList);
SW_API SW_RET SW_ExtractList(SW_LIST *pSrcList, SW_NODE *pStartNode, SW_NODE *pEndNode, SW_LIST *pDstList);
SW_API SW_RET SW_FreeList(SW_LIST *pList);

/** Deprecated APIs */
#define SW_DeleteNode           SW_RemoveNode

#ifdef __cplusplus
}
#endif

#endif

#endif

